package com.kanqiubao.kq;

import android.app.Application;
import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.dueeeke.videoplayer.ijk.IjkPlayerFactory;
import com.dueeeke.videoplayer.player.VideoViewConfig;
import com.dueeeke.videoplayer.player.VideoViewManager;
import com.facebook.common.logging.FLog;
import com.facebook.drawee.backends.pipeline.Fresco;
import com.hjq.toast.ToastUtils;
import com.kanqiubao.kq.utils.AppConfig;
import com.lzy.okgo.OkGo;
import com.tencent.smtt.sdk.QbSdk;


public class ThisAppApplication extends Application {
    private static ThisAppApplication mStudyTwoApplication;

    @Override
    public void onCreate() {
        mStudyTwoApplication = this;
        OkGo.getInstance().init(this);
        super.onCreate();
        ToastUtils.init(this);
        initPlay();
        QbSdk.initX5Environment(this, new QbSdk.PreInitCallback() {
            @Override
            public void onCoreInitFinished() {
            }

            @Override
            public void onViewInitFinished(boolean b) {

            }
        });
        Fresco.initialize(this);
        FLog.setMinimumLoggingLevel(FLog.VERBOSE);
    }

    private void initPlay() {
        //播放器配置，注意：此为全局配置，按需开启
        VideoViewManager.setConfig(VideoViewConfig.newBuilder()
                .setLogEnabled(BuildConfig.DEBUG)//调试的时候请打开日志，方便排错
                .setPlayerFactory(IjkPlayerFactory.create())
//                .setPlayerFactory(ExoMediaPlayerFactory.create())
//                .setRenderViewFactory(SurfaceRenderViewFactory.create())
//                .setEnableOrientation(true)
//                .setEnableAudioFocus(false)
//                .setScreenScaleType(VideoView.SCREEN_SCALE_MATCH_PARENT)
//                .setAdaptCutout(false)
//                .setPlayOnMobileNetwork(true)
//                .setProgressManager(new ProgressManagerImpl())
                .build());
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
    }

    public synchronized static ThisAppApplication getInstance() {
        return mStudyTwoApplication;
    }

    /**
     * 加载默认图
     *
     * @param url
     * @param img
     */
    public static void loadImage(String url, ImageView img) {
        if (img == null || img.getContext() == null) {
            return;
        }
        Glide.with(img).load(AppConfig.ImageUrl(url)).placeholder(R.drawable.default_loading_bg).into(img);

    }

}
